<?php
namespace Admin\Controller;
use Think\Controller;
use Admin\Model\ShopsModel;
use \sinacloud\sae\Storage as Storage;
//商户管理类
class ShopsController extends ApplicationController {
	//修改商户信息
	public function changeinfo(){
		//先取出用户的id
		$buss_id = session("admin_id");
		//如果有post过来的数据
		if (I("post.")) {
			$buss = new ShopsModel('buss','kl_');

			//根据商户的id修改对应商户的信息
			$info=$buss->changeShopsInfo($buss_id,I("post."));
			if($info){
				session('admin_name',$data['bs_name']);
				$this->success("修改成功");
			}
		}else{
			//显示商户信息
			//获取到需要的商户信息
			$buss = new ShopsModel('buss','kl_');
			//根据商户的id获取信息
			// $info=$buss->getShopsInfo($buss_id);
			$info= $buss->find($buss_id);
			$bussext = M("Buss_ext");
			$infoext = $bussext->where('buss='.$buss_id)->find();
			//显示商户
			$this->assign("info",$info);
			$this->assign("infoext",$infoext);
			$this->display("changeinfo");
		}
	}
	//修改logo
	public function changelogo(){
		//从数据库中提取当前用户的图片信息
		//先取出用户的id
		$buss_id = session("admin_id");
		$buss = new ShopsModel('buss','kl_');
		$info=$buss->getBussImgUrl($buss_id);

		$this->assign("logo",$info['logo']);
		$this->assign("shopimg",$info['shopimg']);

		$this->display("changelogo");
		
	}
	//上传文件
	public function upload(){
		$buss_id = session("admin_id");
		//用户上传的文件信息
		$upload_name = $_FILES["file_data"]["name"];    
		$upload_filetype = $_FILES["file_data"]["type"]; 
		$upload_server_name = time().$upload_name; 
		$upload_tmp_address = $_FILES["file_data"]["tmp_name"]; 
		$upload_file_size = $_FILES["file_data"]["size"]; 
		//文件上传
		$s = new Storage();
		$s->putObjectFile($upload_tmp_address, "public", $upload_server_name);
		//判断上传的图片时什么类型
		$type=I("get.type");
		$buss = M("Buss");
		if($type=="logo"){
			$data['logo'] = $s->getUrl("public", $upload_server_name);
			$buss->where("bs_id=".$buss_id)->data($data)->save();
		}else{
			$data['shopimg'] = $s->getUrl("public", $upload_server_name);
			$buss->where("bs_id=".$buss_id)->data($data)->save();
		}
	}

	//修改密码
	public function changepwd(){
		//从数据库中提取当前用户的图片信息
		//如果有post过来的数据，说明是修改密码，进入数据库操作
		$buss_id = session("admin_id");
		$buss=M("Buss");
		if (I("post.oldpwd")) {
			$bussinfo=$buss->find($buss_id);
			//如果旧密码正确
			if($bussinfo['bs_pwd']==I("post.oldpwd")){
				$condition['bs_id'] = $buss_id;
				$data['bs_pwd'] = I("newpwd"); 
				$buss->where($condition)->save($data);
				$this->success("修改成功");
			}else{
				//旧密码不正确
				$this->error("密码不正确");
			}
		}else{
			//没有的话显示修改密码界面
			$this->display("changepwd");
		}
		

	}	  
}


























